Home:ALL Converter>Is it possible to check if a object is equal to a template class without specifying the template type?

Is it possible to check if a object is equal to a template class without specifying the template type?

Ask Time:2020-02-24T01:27:04         Author:Tom

Json Formatter

Suppose I have the class:

template<typename T>
class ChartData {
public:
...

Now I want to check if the object value is a ChartData object:

if (value.type() == typeid(ChartData*))

However this causes the error

argument list for class template is missing

So the compiler is expecting me to put a type at ChartData* however in this condition I'm not interested in the type - I just want to know if the object is a instance of a ChartData object.

Is this possible? If so, how?

Author:Tom,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364882/is-it-possible-to-check-if-a-object-is-equal-to-a-template-class-without-specify
Igor Tandetnik :

Something along these lines:\n\ntemplate <typename T>\nstruct IsChartData : public std::false_type {};\n\ntemplate <typename T>\nstruct IsChartData<ChartData<T>> : public std::true_type {};\n\nif (IsChartData<decltype(value)>()) {...}\n",
2020-02-23T17:38:29
yy